#ifndef ZINGPLAYER_H
#define ZINGPLAYER_H

#include <QMainWindow>
#include <phonon/audiooutput.h>
#include <phonon/seekslider.h>
#include <phonon/mediaobject.h>
#include <phonon/volumeslider.h>
#include <phonon/backendcapabilities.h>
#include <QList>
#include <QNetworkAccessManager>
#include <QFile>
#include <QUrl>
#include <QBuffer>

QT_BEGIN_NAMESPACE
class QAction;
class QTableWidget;
class QLCDNumber;
QT_END_NAMESPACE

//![0]

class ZingPlayer : public QMainWindow
{
//![0]
    Q_OBJECT

public:
    ZingPlayer();

    QSize sizeHint() const {
        return QSize(500, 300);
    }

private slots:
    void addFiles();
    void addUrl();
    void about();
//![1]
    void stateChanged(Phonon::State newState, Phonon::State oldState);
    void tick(qint64 time);
    void sourceChanged(const Phonon::MediaSource &source);
    void metaStateChanged(Phonon::State newState, Phonon::State oldState);
    void aboutToFinish();
    void tableClicked(int row, int column);
//![1]

    void startRequest(QUrl url);
    void downloadMp3(QUrl url, QString fileName);

//    void downloadFile();
//    void cancelDownload();
    void httpFinished();
    void httpReadyRead();
    void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
//    void enableDownloadButton();
//    void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *);
    int addSongToTable(QString title, QString artist, QString album, QString year, QString status);
    void updateSongInfo(int index);

private:
    void setupActions();
    void setupMenus();
    void setupUi();

//![2]
    Phonon::SeekSlider *seekSlider;
    Phonon::MediaObject *mediaObject;
    Phonon::MediaObject *metaInformationResolver;
    Phonon::AudioOutput *audioOutput;
    Phonon::VolumeSlider *volumeSlider;
    QList<Phonon::MediaSource> sources;
//![2]

    QAction *playAction;
    QAction *pauseAction;
    QAction *stopAction;
    QAction *nextAction;
    QAction *previousAction;
    QAction *addFilesAction;
    QAction *addUrlAction;
    QAction *exitAction;
    QAction *aboutAction;
    QAction *aboutQtAction;
    QLCDNumber *timeLcd;
    QTableWidget *musicTable;
    QNetworkReply *reply;
    QNetworkAccessManager qnam;
    QFile *file;
    int currentDownload;
};

#endif
